package com.atguigu.srb.core.controller.api;


import com.atguigu.srb.base.util.JwtUtils;
import com.atguigu.srb.common.result.R;
import com.atguigu.srb.core.entity.TransFlow;
import com.atguigu.srb.core.service.TransFlowService;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 交易流水表 前端控制器
 * </p>
 *
 * @author Atguigu
 * @since 2023-06-30
 */
@RestController
@RequestMapping("/api/core/transFlow")
public class ApiTransFlowController {
    @Resource
    TransFlowService transFlowService;
    @ApiOperation("会员交易记录查询")
    @GetMapping("/list")
    public R getTransFlow(@RequestHeader(value = "token",required = false)String token){
        Long userId = JwtUtils.getUserId(token);
        List<TransFlow> list = transFlowService.list(Wrappers.lambdaQuery(TransFlow.class).eq(TransFlow::getUserId, userId)
                .orderByAsc(TransFlow::getCreateTime));
        return R.ok().data("items",list);
    }
}

